package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.Role;
import cn.wolfcode.crm.service.IRoleService;
import cn.wolfcode.crm.util.JSONResult;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("role")
public class RoleController {
    @Autowired
    IRoleService roleService;

    @RequestMapping("view")
    @RequiresPermissions(value = {"role:view","角色页面"},logical= Logical.OR)
    public String view() {
        return "role";
    }
 
    @RequestMapping("getAll")
    @ResponseBody
    public List<Role> getAll() {
        return roleService.getAll();
    }

 
    @RequestMapping("saveOrUpdate")
    @ResponseBody
    @RequiresPermissions(value = {"role:save","保存角色"},logical= Logical.OR)
    public JSONResult saveOrUpdate(Role role){
        try {
            roleService.saveOrUpdate(role);
        } catch (Exception e) {
            e.printStackTrace();
            return new JSONResult(false,"列表更新失败");
        }
        return new JSONResult(true,"恭喜您执行成功");
    }
    @RequestMapping("getMenuIdByRoleId")
    @ResponseBody
    public List<Long> getMenuIdByRoleId(Long roleId) {
        return roleService.getMenuIdByRoleId(roleId);
    }
}
